package com.telit.firecommand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.firecommand.dao.CommFireOnemapDao;
import com.telit.firecommand.entity.CommFireOnemap;
import com.telit.firecommand.service.ICommFireOnemapService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 火点对应一张图数据 服务实现类
 * </p>
 *
 * @author yummy
 * @since 2022-04-18
 */
@Service
@Transactional
public class CommFireOnemapServiceImpl extends ServiceImpl<CommFireOnemapDao, CommFireOnemap> implements ICommFireOnemapService {

    @Override
    public Long add(CommFireOnemap commFireOnemap){
        baseMapper.insert(commFireOnemap);
        return commFireOnemap.getId();
    }

    @Override
    public void delete(Long id){
        baseMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(Long[] ids){
        if(ids!=null && ids.length>0){
            for(Long id:ids){
                baseMapper.deleteById(id);
            }
        }
    }

    @Override
    public void updateData(CommFireOnemap commFireOnemap){

         baseMapper.updateById(commFireOnemap);
    }


    @Override
    public CommFireOnemap findById(Long id){
        return  baseMapper.selectById(id);
    }

    @Override
    public CommFireOnemap findByPoint(String longitude, String latitude) {
        CommFireOnemap commFireOnemap=baseMapper.findByPoint(longitude,latitude);
        return commFireOnemap;
    }


    @Override
    public IPage<CommFireOnemap> findListByPage(CommFireOnemap commFireOnemap, Integer page, Integer pageCount){
        IPage<CommFireOnemap> commFireOnemapPage = new Page<>(page, pageCount);
        QueryWrapper<CommFireOnemap> wrapper=new QueryWrapper<>();
        if(commFireOnemap !=null){
                if(StringUtils.hasText(commFireOnemap.getPoXiang())){
                wrapper.eq("po_xiang",commFireOnemap.getPoXiang());
                }
                if(StringUtils.hasText(commFireOnemap.getPoWei())){
                wrapper.eq("po_wei",commFireOnemap.getPoWei());
                }
                if(commFireOnemap.getPoDu()!=null){
                wrapper.eq("po_du",commFireOnemap.getPoDu());
                }
                if(StringUtils.hasText(commFireOnemap.getDiLei())){
                wrapper.eq("di_lei",commFireOnemap.getDiLei());
                }
                if(StringUtils.hasText(commFireOnemap.getSenLinLb())){
                wrapper.eq("sen_lin_lb",commFireOnemap.getSenLinLb());
                }
                if(StringUtils.hasText(commFireOnemap.getLingZu())){
                wrapper.eq("ling_zu",commFireOnemap.getLingZu());
                }
                if(StringUtils.hasText(commFireOnemap.getYouShiSz())){
                wrapper.eq("you_shi_sz",commFireOnemap.getYouShiSz());
                }
        }
        return   baseMapper.selectPage(commFireOnemapPage, wrapper);
    }

    @Override
    public  List<CommFireOnemap> searchNoPage(CommFireOnemap commFireOnemap){
        QueryWrapper<CommFireOnemap> wrapper=new QueryWrapper<>();
        if(commFireOnemap !=null){
                if(commFireOnemap.getFireId() !=null && commFireOnemap.getFireId() !=0L){
                    wrapper.eq("fire_id",commFireOnemap.getFireId());
                }
                if(StringUtils.hasText(commFireOnemap.getPoXiang())){
                wrapper.eq("po_xiang",commFireOnemap.getPoXiang());
                }
                if(StringUtils.hasText(commFireOnemap.getPoWei())){
                wrapper.eq("po_wei",commFireOnemap.getPoWei());
                }
                if(commFireOnemap.getPoDu()!=null){
                wrapper.eq("po_du",commFireOnemap.getPoDu());
                }
                if(StringUtils.hasText(commFireOnemap.getDiLei())){
                wrapper.eq("di_lei",commFireOnemap.getDiLei());
                }
                if(StringUtils.hasText(commFireOnemap.getSenLinLb())){
                wrapper.eq("sen_lin_lb",commFireOnemap.getSenLinLb());
                }
                if(StringUtils.hasText(commFireOnemap.getLingZu())){
                wrapper.eq("ling_zu",commFireOnemap.getLingZu());
                }
                if(StringUtils.hasText(commFireOnemap.getYouShiSz())){
                wrapper.eq("you_shi_sz",commFireOnemap.getYouShiSz());
                }
        }
        return baseMapper.selectList(wrapper);

    }
}
